<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>我的订单</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/css.css"/>
</head>

<body>
<style>
    [v-cloak] {
        display: none;
    }
</style>
<div v-cloak id="wrap" class="flex-wrap flex-vertical bg">
    <header>
        <ul>
            <li class="active">
                <i onclick="back()" class="icon iconfont icon-back"></i>
                <span>我的订单</span>
            </li>
        </ul>
    </header>
    <div class="orderpage fixed-header">
        <div>
            <div class="order-list" v-for="(item,index) in list" :key="index">
                <div class="order-list-head">
                    <div class="order-list-headl">订单号：{{item.orderno}}</div>
                    <div class="order-list-headr">{{item.createtime}}</div>
                </div>
                <div class="order-list-body">
                    <div class="order-list-body-img">
                        <img v-if="item.thumb==''" src="../../image/tupian1.jpg" alt="">
                        <img v-else src="../../image/tupian1.jpg" data-cache="no" :data-src="item.thumb | filtersImg"
                             alt=""></div>
                    <div class="order-list-body-right">
                        <div class="order-list-title">
                            {{item.title}}
                        </div>
                        <div class="order-list-prices">
                            <div class="order-list-price">
                                ￥{{item.price}}
                            </div>
                            <div class="order-list-num">
                                x{{item.amount}}
                            </div>
                        </div>
                    </div>
                </div>
                <div class="order-list-footer" v-if="item.status==0">
                    供货订单（审核中）
                </div>
                <div class="order-list-footer" v-if="item.status==1">
                    供货订单（已完成）
                </div>
                <div class="order-list-footer order-yijia order-list-footer1" v-if="item.status==2">
                    <div class="order-list-footerl">
                        <p>状态：议价中</p>
                        <p>数量：{{item.amount}}</p>
                        <p>单价：{{item.price}}</p>
                    </div>
                    <div class="order-list-footerr" @click="querenjiaoyi(item.id)">
                        <span>确认交易</span>
                    </div>
                </div>
                <div class="order-list-footer order-yijia order-list-footer1" v-if="item.status==3">
                    <div class="order-list-footerl">
                        <p>状态：发货中</p>
                        <p>数量：{{item.amount}}</p>
                        <p>单价：{{item.price}}</p>
                    </div>
                    <div class="order-list-footerr" @click="querenfahuo(item.id)">
                        <span>确认发货</span>
                    </div>
                </div>
                <div class="order-list-footer" v-if="item.status==4">
                    供货订单（签收中）
                </div>
                <div class="order-list-footer" v-if="item.status==5">
                    供货订单（支付中）
                </div>
                <div class="order-list-footer" v-if="item.status==7">
                    供货订单（入库中）
                </div>
                <div class="order-list-footer" v-if="item.status==9">
                    供货订单（取消中）
                </div>
            </div>
            <!--0 审核中;1：已完成 ；2：价格确认中；3：发货中；4.签收中；5.支付中；7:入库中;9：取消中-->
            <div class="nolist" v-show="finished">
                没有更多啦
            </div>
        </div>
    </div>
</div>
</body>

</html>
<script src="../../aui/js/aui.js"></script>
<script src="../../script/jquery.min.js"></script>
<script src="../../script/vue2.js"></script>
<script src="../../script/vue-resource.min.js"></script>
<script src="../../script/common.js"></script>
<script type="text/javascript">
    var vm = new Vue({
        el: "#wrap",
        data: {
            uid: '',
            page: 1,
            list: [],
            title: '我的供应',
            pageNumber: 0,
            loading: false, //控制上拉加载的加载动画
            finished: false, //控制在页面往下移动到底部时是否调用接口获取数据
            isLoading: false, //控制下拉刷新的加载动画
        },
        mounted: function () {
            var that = this;
            apiready = function () {
                that.getList(1)
                // api.setRefreshHeaderInfo({
                //     visible: true,
                //     bgColor: '#fff',
                //     textColor: '#666',
                //     textDown: '下拉刷新',
                //     textUp: '释放刷新'
                // }, function (ret, err) {
                //     that.onRefresh()
                // });
                api.addEventListener({name: 'scrolltobottom'}, function (ret, err) {
                    // that.toDoRequest();
                    that.onLoad2()
                });
            };
        },
        methods: {
            getList: function (type) {
                var that = this;
                showProgress();
                var token = $api.getStorage('userInfo').token
                var uid = $api.getStorage('userInfo').id
                api.ajax({
                    url: ajaxRoute.gonglist,
                    method: 'post',
                    data: {
                        values: {
                            token: token,
                            uid: uid,
                            page: that.page
                        }
                    }
                }, function (res, err) {
                    // alert(JSON.stringify(res));
                    if (res.code == 1) {
                        api.hideProgress();
                        if (type == 2) {
                            api.refreshHeaderLoadDone()
                        }
                        if (res.data.length == 0) {
                            api.toast({msg: '暂无内容', location: 'middle'});
                        }
                        that.list = res.data
                        that.$nextTick(function () {
                            // alert('v-for渲染已经完成')
                            cacheDataImg()
                        })
                        // alert(JSON.stringify(that.list));
                    } else {
                        api.hideProgress();
                        api.toast({msg: res.msg, location: 'middle'});
                    }
                });
            },
            querenjiaoyi: function (type) {
                var that = this;
                var token = $api.getStorage('userInfo').token
                api.ajax({
                    url: ajaxRoute.gongagree,
                    method: 'post',
                    data: {
                        values: {
                            token: token,
                            id: type,
                        }
                    }
                }, function (res, err) {
                    // alert(JSON.stringify(res));
                    if (res.code == 1) {
                        api.toast({msg: '确认成功', location: 'middle'});
                        that.getList(1)
                    } else {
                        api.toast({msg: res.msg, location: 'middle'});
                    }
                });
            },
            querenfahuo: function (type) {
                var that = this;
                var token = $api.getStorage('userInfo').token
                api.ajax({
                    url: ajaxRoute.gongdeliver,
                    method: 'post',
                    data: {
                        values: {
                            token: token,
                            id: type,
                        }
                    }
                }, function (res, err) {
                    // alert(JSON.stringify(res));
                    if (res.code == 1) {
                        api.toast({msg: '确认成功', location: 'middle'});
                        that.getList(1)
                    } else {
                        api.toast({msg: res.msg, location: 'middle'});
                    }
                });
            },
            //下拉刷新
            onRefresh: function () {
                var that = this;
                setTimeout(function () {
                    api.refreshHeaderLoadDone()
                    this.page = 1
                    that.getList()
                }, 1000);
            },
            onLoad2: function () {
                // 异步更新数据
                var that = this
                that.page++
                showProgress();
                var token = $api.getStorage('userInfo').token
                var uid = $api.getStorage('userInfo').id
                api.ajax({
                    url: ajaxRoute.gonglist,
                    method: 'post',
                    data: {
                        values: {
                            token: token,
                            uid: uid,
                            page: that.page
                        }
                    }
                }, function (res, err) {
                    if (res.code == 1) {
                        api.hideProgress();
                        var s = res.data
                        for (var i = 0; i < s.length; i++) {
                            that.list.push(s[i])
                        }
                        that.loading = false
                        that.$nextTick(function () {
                            // alert('v-for渲染已经完成')
                            cacheDataImg()
                        })
                        if (res.data.length == 0) {
                            that.loading = false
                            that.finished = true
                        } else {
                            that.loading = false
                        }
                    } else {
                        api.hideProgress();
                        api.toast({msg: res.msg, location: 'middle'});
                    }
                });
            },
        },
        filters: {
            filtersImg(img) {
                var imgs = ajaxUrl + '/' + img
                return imgs;
            }
        },
    })
</script>
